//
//  YYLMainViewController.swift
//  XinlangWeibo
//
//  Created by yangyinglei on 2017/3/26.
//  Copyright © 2017年 yangyinglei. All rights reserved.
//

import UIKit
import SVProgressHUD

class YYLMainViewController: UITabBarController, YYLHomeTabBarDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        setupUI()
    }

    func setupUI() {

        let tabBar = YYLHomeTabBar()
        tabBar.hmDelegate = self
        tabBar.didSelectComposeBtnClosuer = {[weak self] in
            print(self!)
            print("我是闭包传递过来的")
            if YYLUserAccountViewModel.shareViewModel.isLogin {
                let composeView = YYLComposeView()
                
                
                if let weakSelf = self {
                composeView.show(target: weakSelf)
                }
            } else {
                SVProgressHUD.showError(withStatus: "请先登录")
                
            }
        }
        
        self.setValue(tabBar, forKey: "tabBar")
        
        addChildViewController(childController: YYLHomeTableViewController(), imagName: "tabbar_home", title: "首页")
        addChildViewController(childController: YYLMessageTableViewController(), imagName: "tabbar_message_center", title: "消息")
        addChildViewController(childController: YYLDiscoverTableViewController(), imagName: "tabbar_discover", title: "发现")
        addChildViewController(childController: YYLMineTableViewController(), imagName: "tabbar_profile", title: "我的")
    }
    
    func addChildViewController(childController: UIViewController ,imagName: String ,title: String) {
        
        childController.tabBarItem.image = UIImage(named: imagName)
        //设置图片的原始颜色
        childController.tabBarItem.selectedImage = UIImage(named: "\(imagName)_selected")?.withRenderingMode(.alwaysOriginal)
        
        childController.title = title
        
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 14)], for: .normal)
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orange], for: .selected)
        
        let nav = YYLNavigationController(rootViewController: childController)
        
        addChildViewController(nav)

    }
    
    //MARK:代理的实现   
     func didSelectComposeBtnOpration() {
        print("我是代理对象传递过来的")

    }


}
